package de.trebings.gia.entities;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private String name;

	@Persistent
	private String email;

	@Persistent
	private String fbId;

	@Persistent
	private String firstName;

	@Persistent
	private String lastName;

	@Persistent
	private Integer status;

	public static final int NOT_AUTHORIZED = 0;
	public static final int AUTHORIZED = 1;

	@Persistent
	private Date lastLoginDate;

	public Date getLastLoginDate() {
		return lastLoginDate;
	}

	public void updateLoginDate() {
		setLastLoginDate(new Date());
	}

	public void setLastLoginDate(Date lastLoginDate) {
		this.lastLoginDate = lastLoginDate;
	}

	public User() {
		name = "";
		firstName = "";
		lastName = "";
		email = "";
		fbId = "";
		status = NOT_AUTHORIZED;
		lastLoginDate = new Date();
	}

	public String getName() {
		if (!"".equals(name)) {
			return name;
		} else {
			return email;
		}
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFirstName() {
		if (!"".equals(firstName)) {
			return firstName;
		} else {
			return email;
		}
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		if (!"".equals(lastName)) {
			return lastName;
		} else {
			return email;
		}
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFbId() {
		return fbId;
	}

	public void setFbId(String fbId) {
		this.fbId = fbId;
	}

	public long getId() {
		return id;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

}
